package com.open4cn.simulator.core.answer;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ConcurrentLinkedQueue;

/**
 * @author yinxiaopeng
 * @version 1.0.0
 * @company 致景科技
 * @department 飞梭BU/研发
 * @description 指令应答器抽象
 * @Email yinxiaopeng@zj.tech
 * @date 2022-05-03 21:37
 */
public abstract class AbstractAnswer {
    // 当前应答场景
    private String scene;

    // 应答模式
    private AnswerModeEnum answerMode;

    // 手工输入应答队列
    private ConcurrentLinkedQueue<Object> inputQueue;

    // 循环应答
    private Object loop;

    // 应答动作
    private List<AbstractAction> actions;

    /**
     * 更改应答
     *
     * @param values
     */
    public void changeAnswerValue(List<Object> values) {
        // do nothing
    }


    /**
     * ------------------------------------------------------------
     **/
    protected AbstractAnswer(String scene, AnswerModeEnum answerMode) {
        this.scene = scene;
        this.answerMode = answerMode;
        this.inputQueue = new ConcurrentLinkedQueue<>();
    }

    public String getScene() {
        return scene;
    }

    public AnswerModeEnum getAnswerMode() {
        return answerMode;
    }

    public void setAnswerMode(AnswerModeEnum answerMode) {
        this.answerMode = answerMode;
    }

    public void appendInput(Object input) {
        inputQueue.add(input);
    }

    public Object pollInput() {
        return inputQueue.poll();
    }

    public Object getLoop() {
        return loop;
    }

    public void setLoop(Object loop) {
        this.loop = loop;
    }

    public ConcurrentLinkedQueue<Object> getInputQueue() {
        return inputQueue;
    }

    public List<AbstractAction> getActions() {
        return null != actions ? actions : Collections.emptyList();
    }

    public void setActions(List<AbstractAction> actions) {
        this.actions = new ArrayList<>(actions);
    }

    public void appendAction(AbstractAction action) {
        if (null == actions) {
            actions = new ArrayList<>();
        }
        actions.add(action);
    }
}
